package st.business.tepth.business.adapter;

import android.content.Context;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.bean.BusRepairBean;

/**
 * @author zhangyu
 * @date 2019/1/21
 */
public class TimeLineAdapter extends BaseQuickAdapter
        <BusRepairBean.RepairAuditListBean, BaseViewHolder> {
    private int mColorDone;
    private int mColorUnDo;
    private int mColorYellow;

    public TimeLineAdapter(Context context,
                           int layoutResId,
                           @Nullable List<BusRepairBean.RepairAuditListBean> data) {
        super(layoutResId, data);
        mColorDone = context.getResources().getColor(R.color.v_short_diver);
        mColorUnDo = context.getResources().getColor(R.color.v_short_diver_un_do);
        mColorYellow = context.getResources().getColor(R.color.fontColorYellow);
    }

    @Override
    protected void convert(BaseViewHolder helper, BusRepairBean.RepairAuditListBean item) {
        if (helper.getAdapterPosition() == 0) {
            helper.setVisible(R.id.view_left, false);
        } else {
            helper.setVisible(R.id.view_left, true);
        }
        if (helper.getAdapterPosition() == getItemCount() - 1) {
            helper.setVisible(R.id.view_right, false);
        } else {
            helper.setVisible(R.id.view_right, true);
        }
        String date = item.getAdd_time();
        if (date != null) {
            helper.setText(R.id.tv_date, date.substring(5, 11));
        }
        helper.setText(R.id.tv_node_content, item.getStatus_name());
        helper.setText(R.id.tv_time_down, date);
        if (helper.getAdapterPosition() == 0) {
            helper.setVisible(R.id.tv_content_down, true);
            helper.setText(R.id.tv_content_down, "查看报修");
        } else {
            helper.setVisible(R.id.tv_content_down, item.getStatus() == 3);
            helper.setText(R.id.tv_content_down, "查看详情");
        }
        helper.addOnClickListener(R.id.tv_content_down);
        // helper.setVisible(R.id.tv_content_down, item.getContent() != null);
        int finishStatus = item.getFinish_state();
        helper.setBackgroundColor(R.id.view_left,
                finishStatus == 0 ? mColorDone : mColorUnDo
        );
        helper.setBackgroundColor(R.id.view_right,
                finishStatus == 0 ? mColorDone : mColorUnDo
        );
        helper.setBackgroundColor(R.id.tv_date,
                finishStatus == 0 ? mColorYellow : mColorUnDo);
    }
}
